﻿using System.Net;
using System.Net.Mail;

namespace SendToMe
{
    class Mail
    {
        public static void SendMail(string body, params string[] filenames)
        {
            SmtpClient objSmtpClient = new SmtpClient();
            objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
            objSmtpClient.Host = "smtp.21cn.com";
            objSmtpClient.Credentials = new NetworkCredential("SendToTemp", "sendtomytemp");//用户名和密码

            MailMessage objMailMessage = new MailMessage("SendToTemp@21cn.com", "temptester@163.com")
            {
                Subject = "Send To Me",
                Body = body,
                BodyEncoding = System.Text.Encoding.UTF8,
            };

            foreach (var item in filenames)
            {
                objMailMessage.Attachments.Add(new Attachment(item));
            }

            objSmtpClient.Send(objMailMessage);
        }
    }
}
